package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.AddAnswerInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.AnswerActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.AskBean;

public class AskAdapter extends BaseAdapter<AskBean> {
    public AskAdapter(Context context, List<AskBean> items, int layoutResourse) {
        super(context, items, layoutResourse);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        AskViewHolder viewHolder = new AskViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        AskViewHolder viewHolder=(AskViewHolder) holder;
        AskBean askBean=items.get(position);

        final String title = askBean.getAsk_title();
        viewHolder.askitem_title.setText(title);
        final String id = askBean.getAsk_id();
        final String count = askBean.getAnswercount();
        viewHolder.askitem_answercount.setText(count+"条回答");
        viewHolder.askitem_hd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent(context, AddAnswerInfoActivity.class);
                intent1.putExtra("ask_id",id);
                context.startActivity(intent1);
            }
        });

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AnswerActivity.class);
                intent.putExtra("ask_id",id);
                context.startActivity(intent);
            }
        });
    }
}
